import random
import time
# 空的购物车
mycart = []


# 金额
money = input("请初始化您的金额：")
money = int(money)
#优惠券
quan = random.randint(1,10)
print("恭喜得到%d折优惠"%quan)
count = 0
cost = 0

# 1.商品

shop = [
    ["薯条",2.5],
    ["辣条",3.5],
    ["洗衣机",1200],
    ["Mac pc",12000],
    ["联想电脑",4500],
    ["Iphone 14 pro max",8888],
    ["华为 mate pro 平板",2000],
    ["驴肉火烧",15],
    ["牛肉干",50],
    ["泰国榴莲",45],
    ["六安瓜片",100],
]

while True:
    print("------------------欢迎来到商城----------------------")
    #  展示
    for index,value in enumerate(shop):
        print(index,value)

    chose = input("请输入您要买的商品编号：")

    if chose == "q" or chose == "Q":
        print("ByeBye!欢迎下次光临！")
        break
    elif  chose.isdigit():  #  "56"  --> 56   True   False
        # 买入操作
        chose = int(chose)  # 2
        if chose >= len(shop) or chose < 0:
            print("对不起，没这个商品！别瞎弄!")
        else:
            if money < shop[chose][1]*quan*0.1:
                print("对不起，钱不够")
            else:
                mycart.append(shop[chose])
                money = money - shop[chose][1]*quan*0.1
                cost = cost + shop[chose][1]*quan*0.1
                count = count +1
                print("恭喜！购买成功！您的余额还剩：",money)

    else:
        print("没有这个商品！别瞎输入！")

print("-----------------您的购物小条请拿好---------------------")
for index,value in enumerate(mycart):
    print(index,value)
data = time.time()
date_str = time.strftime("%y-%m-%d %H:%M:%S",time.localtime(data))

print("时间：",date_str)
print("购物数量：",count)
print("总花费：",cost)
print("----------------------------------------------------")
print("您的余额还剩：{:.2f}￥".format(money))





























